﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace AppWorks.Exceptions
{
    class InstanceNotFoundInEnvironmentConfigurationException : EnvironmentException
    {
        public Type RequestedType
        {
            get;
            private set;
        }

        public InstanceNotFoundInEnvironmentConfigurationException(Type requestedType)
            : this(requestedType, requestedType != null ? BuildDefaultMessage(requestedType) : null)
        {
        }

        public InstanceNotFoundInEnvironmentConfigurationException(Type requestedType, string message)
            : this(requestedType, message, null)
        {
        }


        public InstanceNotFoundInEnvironmentConfigurationException(Type requestedType, string message, Exception inner)
            : base(message, inner)
        {
            RequestedType = requestedType;
        }

        protected InstanceNotFoundInEnvironmentConfigurationException(
                SerializationInfo info,
                StreamingContext context)
            : base(info, context)
        {
        }

        private static string BuildDefaultMessage(Type requestedType)
        {
            return String.Format("Could not find requested type {0} in the NcqrsEnvironment configuration. Make sure that " +
                                 "the NcqrsEnvironment is configured correctly or that defaults are correctly set.", requestedType.FullName);
        }
    }
}
